import 'package:flutter/material.dart';
import '../internals/enums.dart';

/// 经典的上拉加载底部指示器。
class ClassicFooter extends StatelessWidget {
  final LoadStatus status;
  final VoidCallback? onRetry;

  const ClassicFooter({super.key, required this.status, this.onRetry});

  @override
  Widget build(BuildContext context) {
    Widget indicator;
    String text;

    // 根据不同状态显示不同的文本和图标
    switch (status) {
      case LoadStatus.idle:
        text = '上拉加载更多';
        indicator = const Icon(Icons.arrow_upward, size: 20, color: Colors.grey);
        break;
      case LoadStatus.loading:
        text = '正在加载...';
        indicator = const SizedBox(
          width: 20,
          height: 20,
          child: CircularProgressIndicator(strokeWidth: 2.0),
        );
        break;
      case LoadStatus.noMoreData:
        text = '--- 我是有底线的 ---';
        indicator = const SizedBox.shrink(); // 没有更多数据时，不显示图标
        break;
      case LoadStatus.failed:
        text = '加载失败，点击重试';
        indicator = const Icon(Icons.error_outline, size: 20, color: Colors.red);
        // 加载失败时，提供点击重试功能
        return InkWell(
          onTap: onRetry,
          child: _buildContent(indicator, text),
        );
    }
    return _buildContent(indicator, text);
  }

  Widget _buildContent(Widget indicator, String text) {
    return SizedBox(
      height: 55, // 底部默认高度
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          if (indicator is! SizedBox) indicator, // 优化：仅在有图标时显示
          if (indicator is! SizedBox) const SizedBox(width: 16),
          Text(text, style: const TextStyle(color: Colors.grey)),
        ],
      ),
    );
  }
}
